﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using Microsoft.VisualStudio.TextManager.Interop;
using Microsoft.VisualStudio;
using System.Runtime.InteropServices;

namespace PovTeam.Pkg_PovrayProject
{
    [Guid("d04d90b8-d52e-45e7-ac29-f16a1a125e1c")]
    class PovLanguageService : IVsLanguageInfo, IVsProvideColorableItems//, IVsLanguageDebugInfo
    {
        class ColorItem : IVsColorableItem
        {
            private string name;
            private FONTFLAGS fontFlags;
            private COLORINDEX foreground;
            private COLORINDEX background;

            public ColorItem(string name, FONTFLAGS fontFlags, COLORINDEX foreground, COLORINDEX background)
            {
                this.name = name;
                this.fontFlags = fontFlags;
                this.foreground = foreground;
                this.background = background;
            }

            public int GetDefaultColors(COLORINDEX[] piForeground, COLORINDEX[] piBackground)
            {
                piForeground[0] = foreground;
                piBackground[0] = background;
                return VSConstants.S_OK;
            }

            public int GetDefaultFontFlags(out uint pdwFontFlags)
            {
                pdwFontFlags = (uint)fontFlags;
                return VSConstants.S_OK;
            }

            public int GetDisplayName(out string pbstrName)
            {
                pbstrName = name;
                return VSConstants.S_OK;
            }

            
        }

       

        public Pkg_PovrayProjectPackage Package
        {
            get { return package; }
        }

        Pkg_PovrayProjectPackage package;   

        private ColorItem[] colorItems = new ColorItem[] 
        {
            new ColorItem("placehlder", FONTFLAGS.FF_DEFAULT, COLORINDEX.CI_RED, COLORINDEX.CI_USERTEXT_BK),
            new ColorItem("Keyword", FONTFLAGS.FF_DEFAULT, COLORINDEX.CI_BLUE, COLORINDEX.CI_USERTEXT_BK),
            new ColorItem("Operator", FONTFLAGS.FF_DEFAULT, COLORINDEX.CI_MAROON, COLORINDEX.CI_USERTEXT_BK),
            new ColorItem("Number", FONTFLAGS.FF_DEFAULT, COLORINDEX.CI_DARKBLUE, COLORINDEX.CI_USERTEXT_BK),
            new ColorItem("Macro", FONTFLAGS.FF_DEFAULT, COLORINDEX.CI_MAGENTA, COLORINDEX.CI_USERTEXT_BK),
            new ColorItem("String", FONTFLAGS.FF_DEFAULT, COLORINDEX.CI_PURPLE, COLORINDEX.CI_USERTEXT_BK),
            new ColorItem("Directive", FONTFLAGS.FF_DEFAULT, COLORINDEX.CI_CYAN, COLORINDEX.CI_USERTEXT_BK),
            new ColorItem("Identifier", FONTFLAGS.FF_DEFAULT, COLORINDEX.CI_DARKGRAY, COLORINDEX.CI_USERTEXT_BK),
            new ColorItem("Comment", FONTFLAGS.FF_DEFAULT, COLORINDEX.CI_DARKGREEN, COLORINDEX.CI_USERTEXT_BK),
        };

        public PovLanguageService(Pkg_PovrayProjectPackage package)
        {
            // TODO: Complete member initialization
            this.package = package;
        }
        #region IVsLanguageInfo Members

        public int GetCodeWindowManager(IVsCodeWindow pCodeWin, out IVsCodeWindowManager ppCodeWinMgr)
        {
            ppCodeWinMgr = new PovCodeWindowManager(pCodeWin, this);
            return VSConstants.S_OK;
        }

        public int GetColorizer(IVsTextLines pBuffer, out IVsColorizer ppColorizer)
        {
            ppColorizer = new PovColorizer(pBuffer);
            return VSConstants.S_OK;
        }

        public int GetFileExtensions(out string pbstrExtensions)
        {
            pbstrExtensions = ".pov;.inc";
            return VSConstants.S_OK;
        }

        public int GetLanguageName(out string bstrName)
        {
            bstrName = "Pov-ray SDL";
            return VSConstants.S_OK;
        }

        #endregion

        #region IVsProvideColorableItems Members

        public int GetColorableItem(int iIndex, out IVsColorableItem ppItem)
        {
            ppItem = colorItems[iIndex];
            return VSConstants.S_OK;
        }

        public int GetItemCount(out int piCount)
        {
            piCount = colorItems.Length - 1;
            return VSConstants.S_OK;
        }

        #endregion

        #region IVsLanguageDebugInfo Members

        public int GetLanguageID(IVsTextBuffer pBuffer, int iLine, int iCol, out Guid pguidLanguageID)
        {
            throw new NotImplementedException();
        }

        public int GetLocationOfName(string pszName, out string pbstrMkDoc, TextSpan[] pspanLocation)
        {
            throw new NotImplementedException();
        }

        public int GetNameOfLocation(IVsTextBuffer pBuffer, int iLine, int iCol, out string pbstrName, out int piLineOffset)
        {
            throw new NotImplementedException();
        }

        public int GetProximityExpressions(IVsTextBuffer pBuffer, int iLine, int iCol, int cLines, out IVsEnumBSTR ppEnum)
        {
            throw new NotImplementedException();
        }

        public int IsMappedLocation(IVsTextBuffer pBuffer, int iLine, int iCol)
        {
            throw new NotImplementedException();
        }

        public int ResolveName(string pszName, uint dwFlags, out IVsEnumDebugName ppNames)
        {
            throw new NotImplementedException();
        }

        public int ValidateBreakpointLocation(IVsTextBuffer pBuffer, int iLine, int iCol, TextSpan[] pCodeSpan)
        {
            throw new NotImplementedException();
        }

        #endregion
    }
}
